#include "head.h"
int server_menu(int net_fd,self_defined_pro_t *mes){
    printf("server_menu: 1 : \n");
    int ret = recv(net_fd,mes,sizeof(self_defined_pro_t),MSG_WAITALL);
    printf("server_menu: 4 : %d \n", ret);

    self_defined_pro_t *send_mes=(self_defined_pro_t *)calloc(1,sizeof(self_defined_pro_t));
    char *path=strtok(mes->message,"=");
    path=strtok(NULL,"&");
    char *username=strtok(NULL,"=");
    username=strtok(NULL,"&");
    char *password=strtok(NULL,"=");
    password=strtok(NULL,"&");
    int file_fd=open("user.txt",O_RDWR|O_CREAT,0666);
    write(file_fd,username,sizeof(username));
    write(file_fd,password,sizeof(password));
    close(file_fd);
    if(mes->cmd==6){
        mkdir(path,0666);
        send_mes->cmd=-1;
        send_mes->message_len=6;
        send_mes->para_num=1;
        strcpy(send_mes->message,"注册成功！\n");
        send(net_fd,send_mes,sizeof(self_defined_pro_t),MSG_NOSIGNAL);
        return 1;
    }
    send_mes->cmd=-1;
    send_mes->message_len=6;
    send_mes->para_num=1;
    strcpy(send_mes->message,"登录成功！\n");
    send(net_fd,send_mes,sizeof(self_defined_pro_t),MSG_NOSIGNAL);
    return 0;
}
int initsocket(int *socket_fd){
    char *ip;
    char *port;
    read_log_file(ip,port);
    struct sockaddr_in socketaddr;
    *socket_fd=socket(AF_INET,SOCK_STREAM,0);
    socketaddr.sin_family=AF_INET;
    socketaddr.sin_port=htons(atoi(port));
    socketaddr.sin_addr.s_addr=inet_addr(ip);
    int reuse = 1;
    setsockopt(*socket_fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse));
    bind(*socket_fd,(struct sockaddr*)&socketaddr,sizeof(socketaddr));
    listen(*socket_fd,10);
    return 0;
}
void read_log_file(char *ip,char*port){

}
